﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;

using WeChatDemo.Models;
using WeChatDemo.Utils;
using AutoMapper;
using AutoMapper.Data;

namespace WeChatDemo.DataProvider
{
    public class DAOThumbup:DAOBase
    {
        private static string tableName = "Thumbup";

        public static IEnumerable<Thumbup> GetAllList()
        {
            IEnumerable<Thumbup> _list = ReaderToList<Thumbup>("", tableName);
            
            return _list;
        }

        public static bool Add(Thumbup model)
        {
            bool flag = false;

            string _sqlString = $"INSERT INTO Thumbup(OpenID, NickName, ArticleID) VALUES('{model.OpenID}','{model.NickName}','{model.ArticleID}')";

            flag = SqlHelper.ExecuteNonQuery(_connectionString, CommandType.Text, _sqlString) == 0 ? false : true;

            return flag;
        }

        public static bool Delete(int id)
        {
            bool flag = false;
            string _sqlString = $"DELETE FROM Thumbup WHERE ThumbupID = {id}";

            flag = SqlHelper.ExecuteNonQuery(_connectionString, CommandType.Text, _sqlString) == 0 ? false : true;

            return flag;
        }

    }
}